package com.ewanghuiju.app.ui.main.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.response.HistoryRecordResponBean;
import com.ewanghuiju.app.util.StringUtil;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

/**
 * @author sj  qq:751943509
 * @class 历史记录
 * @time 2020/2/20
 */
public class HistoryRecordAdapter extends BaseMultiItemQuickAdapter<HistoryRecordResponBean, BaseViewHolder> {

    public HistoryRecordAdapter(List<HistoryRecordResponBean> data) {
        super(data);
        addItemType(HistoryRecordResponBean.HISTORY_RECORD_YHQ, R.layout.item_mail_shop);
        addItemType(HistoryRecordResponBean.HISTORY_RECORD_PT, R.layout.item_history_record_pintuan);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected void convert(BaseViewHolder helper, HistoryRecordResponBean item) {
//        if (helper.getLayoutPosition() == 0 && helper.getLayoutPosition() == getData().size()) {
//            helper.setBackgroundRes(R.id.item_main, R.drawable.corner_white_9);
//        } else if (helper.getLayoutPosition() == 0) {
//            helper.setBackgroundRes(R.id.item_main, R.drawable.corner_white_top_9);
//        } else if (helper.getLayoutPosition() == getData().size()) {
//            helper.setBackgroundRes(R.id.item_main, R.drawable.corner_white_bottom_9);
//        }
        switch (helper.getItemViewType()) {
            case HistoryRecordResponBean.HISTORY_RECORD_YHQ:
                //优惠券
                TextView tv_title = helper.getView(R.id.tv_shop_title);
                StringUtil.getTextStrFormat(tv_title, "AA", item.getTitle());
                helper.setText(R.id.tv_spe_price, item.getSpejia());
                helper.setText(R.id.tv_buynum, item.getNum() + "人购买");
                TextView tv_yuan = helper.getView(R.id.tv_yuan_price);
                tv_yuan.setText("￥" + item.getYuanjia());
                helper.setText(R.id.tv_yhq, item.getYhq() + "元券");
                helper.setText(R.id.tv_ygz, "预估赚 ￥" + item.getYgz());
                helper.setText(R.id.tv_sjz, "升级赚 ￥" + item.getSjz());
                tv_yuan.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
                RoundedImageView riv = helper.getView(R.id.riv_item_icon);
                ImageView iv_lab = helper.getView(R.id.iv_lab);
                ImageLoader.load(mContext, item.getImg(), riv);
                ImageLoader.load(mContext, item.getStatus() == 0 ? R.mipmap.icon_taobao_small : R.mipmap.icon_tianmao_small, iv_lab);
                break;

            case HistoryRecordResponBean.HISTORY_RECORD_PT:
                //拼团
                TextView tv_pt_title = helper.getView(R.id.tv_shop_title);
                StringUtil.getTextStrFormat(tv_pt_title, item.getTuansum() == 0 ? "" : item.getTuansum() + "人团", item.getTitle());
                helper.setText(R.id.tv_title_icon, item.getTuansum() == 0 ? "" : item.getTuansum() + "人团");
                helper.setText(R.id.tv_pintuan_no, "拼团号：714711");
                RoundedImageView pt_riv = helper.getView(R.id.riv_item_icon);
                ImageLoader.load(mContext, item.getImg(), pt_riv);
                View line = helper.getView(R.id.line);
                break;
        }
    }
}
